import axios from "axios";
export function request(config) {
  const insterce = axios.create({
    // baseURL: 'http://localhost:3001/api',
    baseURL: 'https://www.qwex.top/api',
    timeout: 5000
  })
  insterce.interceptors.request.use(config => {
    const token = JSON.parse(window.localStorage.getItem('token'))
    if (token) {
      console.log(token.time);
      console.log(Date.now());
      if (token.time > Date.now()) {
        config.headers.authorization = 'Bearer ' + token.token
      } else {
        window.localStorage.clear()
      }
    }
    return config
  })
  insterce.interceptors.response.use(res => {
    return res.data ? res.data : res
  })
  return insterce(config)
}
